package com.tongtong.stsuserapi.controller;

import com.tongtong.stscommon.message.STSMessage;
import com.tongtong.stsuserapi.service.base.UserService;
import com.tongtong.stsuserapi.service.register.CaptchaService;
import com.tongtong.stsuserapi.service.register.UserRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 注册控制器
 */
@Api(tags="注册接口")
@RestController
@RequestMapping("/sts/register")
public class RegisterController {

	@Autowired
	UserRegisterService registerService;

	@Autowired
	CaptchaService captchaService;

	@Autowired
	UserService userService;

	@ApiOperation(value="注册用户",notes="需要先申请短信验证码，然后通过短信验证码注册")
	@PostMapping("/create")
	public STSMessage registerByTelephone(String phoneNumber, String captcha, String password) {
		return registerService.RegisterByTelephone(phoneNumber,captcha,password);
	}

	@ApiOperation("申请验证码")
	@PostMapping("/captcha")
	public STSMessage applyCaptcha(String phoneNumber) {
		return captchaService.applyCaptcha(phoneNumber);
	}

	@ApiOperation("检查手机号是否已注册")
	@GetMapping("/check/phone")
	public STSMessage checkPhoneNumber(String phoneNumber) {
		return registerService.checkPhoneNumber(phoneNumber);
	}

	@ApiOperation("检查用户名是否已注册")
	@GetMapping("/check/username")
	public STSMessage checkUsername(String username) {
		return registerService.checkUsername(username);
	}

	@ApiOperation("校验短信验证码")
	@GetMapping("/captcha")
	public STSMessage verifyCaptcha(String phoneNumber, String captcha) {
		return captchaService.verifyCaptcha(phoneNumber,captcha);
	}

	@ApiOperation("找回密码")
	@PatchMapping("/retrieve")
	public STSMessage retrievePassword(String phoneNumber, String captcha, String password) {
		return userService.retrievePassword(phoneNumber, captcha, password);
	}

}
